import { EventHttp } from "../../../http/event"
import { computed, ref, inject } from "vue"
/* 右上角折线图 */
const lineData = ref([])
let res = await EventHttp.getLineData()

export const getEventLine = () => {
  if (res.code == 200) {
    /*  const reload = inject("reload")
    reload() */
    //console.log(res.result)
    lineData.value = res.result
  }
  const lineOption = computed(() => {
    return {
      xAxis: {
        type: "category",
        data: lineData.value.map((d) => d.date),
      },
      yAxis: {
        type: "value",
      },
      series: [
        {
          data: lineData.value.map((d) => d.number),
          type: "line",
          markPoint: {
            data: [{ type: "max" }],
          },
          markLine: { data: [{ type: "average" }] },
          smooth: true,
          itemStyle: { normal: { label: { show: true } } },
        },
      ],
      title: {
        text: "近7天每天发生事件数",
        textStyle: {
          color: "grey",
        },
      },
      toolbox: {
        feature: {
          /* 实现图表的缩放 */
          dataZoom: {},
          /* 实现导出图片 */
          saveAsImage: {},
        },
      },
      grid: {
        bottom: "10%",
        top: "30%",
      },
    }
  })
  return {
    lineOption,
    lineData,
  }
}
